# syntax=docker/dockerfile:1
FROM debian:bullseye AS builder

RUN apt-get update && apt-get install --yes git cmake g++ libcurl4-openssl-dev

RUN mkdir /workspace
WORKDIR /workspace
RUN git clone https://github.com/ggerganov/llama.cpp.git

WORKDIR /workspace/llama.cpp

# GGML_RPC=ON: Builds RPC support
# BUILD_SHARED_LIBS=OFF: Don't rely on shared libraries like libggml
RUN cmake . -DGGML_RPC=ON -DBUILD_SHARED_LIBS=OFF -DGGML_DEBUG=1
RUN cmake --build . --config Release --parallel 8

RUN ldd bin/rpc-server

FROM gcr.io/distroless/cc-debian12:nonroot

COPY --from=builder /workspace/llama.cpp/bin/rpc-server /rpc-server

ENTRYPOINT ["/rpc-server"]
